﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class AverageWeighedCompletionTime : Objective
    {
        public AverageWeighedCompletionTime()
            : base()
        {
        }
        public AverageWeighedCompletionTime(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }
        protected override void Logic()
        {
            double averageWeighedCompletionTime = 0;
            double totalWeighedCompletionTime = 0;


            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {
                totalWeighedCompletionTime = totalWeighedCompletionTime + (order.Weight * order.EndDate);
            }


            averageWeighedCompletionTime = totalWeighedCompletionTime / SchEduData.Order.Count;

            GeneratePerformanceRow();

            performance.Value = Math.Round(averageWeighedCompletionTime,2);

        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();
            validators.Add(new OrderEndDateValidator(SchEduData));
            validators.Add(new OrderWeightValidator(SchEduData));
        }


        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Average Weighed Completion Time";
                aboutInfo.Guid = new Guid("{9FCF0FCC-F810-4d18-A31F-C63B2AFB5D8B}");
                aboutInfo.Description = Resources.AverageWeighedCompletionTimeDescription;
                return aboutInfo;
            }
        }

    }
}
